/*
 * Copyright 2009, 2010, YUNNAN Co-soft Information Technology Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* 
 * @author:  Ruan Ao.
 * @version: 18 May,2010.
 */

/*
     *为每个service tab 绑定鼠标事件:mouseover,mouseout
     **/
function bindMouseEvents(){
    for(var i=2;i<=5;i++){
        var service = document.getElementById("service"+i);
        $(service).bind("mouseover",{
            "obj": service,
            "tab":i
        },setColorImage);
        $(service).bind("mouseout",{
            "obj": service,
            "tab":i
        },setBlackImage);
    }
}

function setAsFirst(objId){
     $("#"+objId).click();
}

/* add arr_white.gif*/
function selectPage(){
    $("#contentDiv").attr("scrollLeft",0);
    $("#araIntroductionLabel").css("color", "white");
    $("#araIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
    $("#javaIntroductionLabel").css("color", "white");
    $("#javaIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
    $("#bprsIntroductionLabel").css("color", "white");
    $("#bprsIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
    $("#frontEndEngineerIntroductionLabel").css("color", "white");
    $("#frontEndEngineerIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
    $("#homePageLabel").css("color", "white");
}
/*
 *Show our service's introduction.
 **/
function showServiceAbstract(tab){
    //var serviceList = $("#servicesList");
    for(var i=1;i<=5;i++){
        var $serviceAbstract = $("#service"+i+"Abstract");
        var img = document.getElementById("service"+i);
        if( i == tab){
            $serviceAbstract.show();
            $(img).css("background-position",(-179 * (tab - 1))+ "px -210px");
            $(img).unbind("mouseover",setColorImage);
            $(img).unbind("mouseout",setBlackImage);
        }
        else{
            $serviceAbstract.hide();
            $(img).css("background-position",(-179 * (i -1 ))+"px  0px");
            $(img).bind("mouseover",{
                "img": img,
                "tab":i
            },setColorImage);
            $(img).bind("mouseout",{
                "img": img,
                "tab":i
            },setBlackImage);
        }
    }
}


function setBlackImage(event){
    var tab =event.data.tab;
    var obj= document.getElementById("service"+tab);
    $(obj).css("background-position",  (-179 * (tab -1 )) +"px 0px");
}

function setColorImage(event){
    var tab =event.data.tab;
    var obj= document.getElementById("service"+tab);
    $(obj).css("background-position",(-179 * (tab - 1))+ "px -105px");
}

function gotoPage(parentId,pageId,direction) {
    var obj=document.getElementById(pageId);
    var left=obj.offsetLeft;
    var top=obj.offsetTop;
    var $wrapper = $("#" + parentId);
    if(direction == "horizontal"){
        $wrapper.animate({
            scrollLeft: left
        }, 500);
        $("#nav").children("a").children("span").css("color", "");
        var menuLabelId = $("#" + pageId + "Label");
        menuLabelId.css("color", "white");
    }
    else{
        $wrapper.animate({
            scrollTop: top
        }, 500);
        
        var technologiesLabelId = $("#" + pageId + "Label");        
        $("#ourTechnology-list").children("div").children("span").css("color", "");
        $("#ourTechnology-list").children("div").children("a").remove();

        $("#services-list").children("div").children("span").css("color", "");
        $("#services-list").children("div").children("a").remove();

        $("#teamMembers-list").children("div").children("span").css("color", "");
        $("#teamMembers-list").children("div").children("a").remove();

        $("#careers-list").children("div").children("span").css("color", "");
        $("#careers-list").children("div").children("a").remove();

        //set selected title font-color
        technologiesLabelId.css("color", "white");
        technologiesLabelId.after("<a><img src = 'styles/images/arr_white.gif'></a>");

        if(parentId == "teamMembersIntroduction"){
            $("#javaIntroductionLabel").css("color", "white");
            $("#javaIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
            $("#bprsIntroductionLabel").css("color", "white");
            $("#bprsIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
            $("#frontEndEngineerIntroductionLabel").css("color", "white");
            $("#frontEndEngineerIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
        }
        if(parentId == "ourTechnologyIntroduction"){
            $("#araIntroductionLabel").css("color", "white");
            $("#araIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
            $("#bprsIntroductionLabel").css("color", "white");
            $("#bprsIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
            $("#frontEndEngineerIntroductionLabel").css("color", "white");
            $("#frontEndEngineerIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
        }
        if(parentId == "servicesIntroduction"){
            $("#araIntroductionLabel").css("color", "white");
            $("#araIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
            $("#javaIntroductionLabel").css("color", "white");
            $("#javaIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
            $("#frontEndEngineerIntroductionLabel").css("color", "white");
            $("#frontEndEngineerIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
        }
        if(parentId == "careersIntroduction"){
            $("#javaIntroductionLabel").css("color", "white");
            $("#javaIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
            $("#bprsIntroductionLabel").css("color", "white");
            $("#bprsIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
            $("#araIntroductionLabel").css("color", "white");
            $("#araIntroductionLabel").after("<a><img src = 'styles/images/arr_white.gif'></a>");
        }
    }
}

/*
 *
 **/
function gotoServiceIntroduction(pageId){
    
    var contentDiv = $("#contentDiv");
    var sericePage = document.getElementById("servicePage");
    var obj=document.getElementById(pageId);
    var top=obj.offsetTop;
    var $wrapper = $("#servicesIntroduction");
    
    contentDiv.animate({
        scrollLeft: sericePage.offsetLeft
    },200);

    $wrapper.animate({
        scrollTop: top
    }, 500);
    $("#nav").children("a").children("span").css("color", "");
    $("#servicePageLabel").css("color", "white");
    $("#services-list").children("div").children("span").css("color", "");
    $("#services-list").children("div").children("a").remove();
    $("#" + pageId +"Label").css("color", "white");
    $("#" + pageId +"Label").after("<a><img src = 'styles/images/arr_white.gif'></a>");
}
